<?php
namespace app\home\controller;
use think\Controller;
use think\Session;
use think\Db;
use think\Request;
class Article extends Controller{
   /*
    * 文章主页面
    * 
    * */
    public function index(){
        $userSession = Session::get("USERS");
        //分类查询
        $acTcls = Db::table("articlecats")->select();
        //先获取全部文章
        $row  = Db::table("article")->where("article_del = 0")->order('article_time desc')->paginate(5);
        $page = $row->render();
        $this->view->assign("user_id",$userSession['user_id']);
        $this->view->assign("row",$row);
        $this->view->assign('page', $page);
        $this->view->assign("acTcls",$acTcls);
        return $this->fetch();
        
    }
    
    /*
     * 
     * 文章详情页面
     * */
   public function details(){
       $userSession = Session::get("USERS");
       $this->view->assign("user_id",$userSession['user_id']);
       $request = Request::instance()->get();
       $id = $request['id'];
       $row = Db::table("article")->where("article_id = $id")->find();
       $this->view->assign("row",$row);

       return $this->fetch();

   }

    /*
       *
       * 文章分类查询
* */
    public function select(){
        //分类查询
        $userSession = Session::get("USERS");
        $request = Request::instance()->get();
        $id = $request['id'];
        $acTcls = Db::table("articlecats")->select();
        $nameid = Db::table("articlecats")->where("class_id = $id")->find();
        $row  = Db::table("article")->where("article_del = 0 And pid = $id")->order('article_time desc')->paginate(5);
        $page = $row->render();
        $this->view->assign("user_id",$userSession['user_id']);
        $this->view->assign("row",$row);
        $this->view->assign('page', $page);
        $this->view->assign('nameid', $nameid);
        $this->view->assign("acTcls",$acTcls);
        return $this->fetch();

    }


}